package com.xydtech.ecard.ftp.controller;

import com.xydtech.common.annotation.Log;
import com.xydtech.common.core.controller.BaseController;
import com.xydtech.common.core.domain.AjaxResult;
import com.xydtech.common.core.page.TableDataInfo;
import com.xydtech.common.core.text.Convert;
import com.xydtech.common.enums.BusinessType;
import com.xydtech.common.utils.poi.ExcelUtil;
import com.xydtech.ecard.ftp.domain.FtpDepositLoanRateConfig;
import com.xydtech.ecard.ftp.service.IFtpDepositLoanRateConfigService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: liliya
 * @Description: ftp_deposit_loan_rate_config FTP存贷款收益率曲线
 * @Date: Created in 2023/8/18 10:11
 * @Modified:
 */
@Controller
@RequestMapping("/ecard/ftp/rate/config")
public class FtpDepositLoanRateConfigController extends BaseController {

    private IFtpDepositLoanRateConfigService ftpDepositLoanRateConfigService;
    public FtpDepositLoanRateConfigController(IFtpDepositLoanRateConfigService ftpDepositLoanRateConfigService) {
        this.ftpDepositLoanRateConfigService = ftpDepositLoanRateConfigService;
    }

    private String prefix = "ecard/ftp/rate";

    @RequiresPermissions("ftpRate:info:view")
    @GetMapping()
    public String redirect()
    {
        return prefix + "/depositLoanRateConfig";
    }

    /**
     * 查询FTP存贷款收益率曲线表列表
     */
    @RequiresPermissions("ftpRate:info:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FtpDepositLoanRateConfig config){
        startPage();
        //TODO 参数暂时不用
        List<FtpDepositLoanRateConfig> list = ftpDepositLoanRateConfigService.selectBaseList(config);
        return getDataTable(list);
    }

    /**
     * 导出
     */
    @RequiresPermissions("ftpRate:info:export")
    @Log(title = "FTP存贷款收益率曲线", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FtpDepositLoanRateConfig config){
        //TODO 参数暂时不用
        List<FtpDepositLoanRateConfig> list = ftpDepositLoanRateConfigService.selectBaseList(config);
        ExcelUtil<FtpDepositLoanRateConfig> util = new ExcelUtil<>(FtpDepositLoanRateConfig.class);
        return util.exportExcel(list, "FTP存贷款收益率曲线");
    }

    /**
     * 新增跳转
     * @return
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存
     */
    @RequiresPermissions("ftpRate:info:add")
    @Log(title = "参数管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@Validated FtpDepositLoanRateConfig config)
    {
        config.setCreateBy(getLoginName());
        config.setUpdateBy(getLoginName());
        return toAjax(ftpDepositLoanRateConfigService.insertBase(config));
    }

    /**
     * 修改跳转
     */
    @GetMapping("/edit/{configId}")
    public String edit(@PathVariable("configId") Integer configId, ModelMap mmap){
        mmap.put("ftpDepositLoanRateConfig", ftpDepositLoanRateConfigService.selectBaseById(configId));
        return prefix + "/edit";
    }

    /**
     * 修改
     */
    @RequiresPermissions("ftpRate:info:edit")
    @Log(title = "参数管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@Validated FtpDepositLoanRateConfig config){
        config.setUpdateBy(getLoginName());
        return toAjax(ftpDepositLoanRateConfigService.updateBase(config));
    }

    /**
     * 删除
     */
    @RequiresPermissions("ftpRate:info:remove")
    @Log(title = "参数管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids){
        Long[] configIds = Convert.toLongArray(ids);
        ftpDepositLoanRateConfigService.deleteBaseByIds(configIds);
        return success();
    }

    public IFtpDepositLoanRateConfigService getFtpDepositLoanRateConfigService() {
        return ftpDepositLoanRateConfigService;
    }

    public void setFtpDepositLoanRateConfigService(IFtpDepositLoanRateConfigService ftpDepositLoanRateConfigService) {
        this.ftpDepositLoanRateConfigService = ftpDepositLoanRateConfigService;
    }
}
